<?php
include_once "xAP-functions/webincludes.php";

$ip=$_SERVER["REMOTE_ADDR"];




// clean unwanted panels
for($c=1;$c<4;$c++){
	$i=1;
	foreach($_GET["Col".$c] as $value){
		if(substr($value,0,2)=="xx"){
			$newid[]=intval(substr($value,2));
		}
	}
}
$results=dbquery("select LocationID from xAP_Widget_Location where IP='".$ip."'");
foreach($results as $row){
	if(in_array($row["LocationID"],$newid)==False){
		dbexec("delete from xAP_Widget_location where LocationID=".$row["LocationID"]);
	}
}



for($c=1;$c<4;$c++){
	$i=1;
	foreach($_GET["Col".$c] as $value){
		if(substr($value,0,2)=="xx"){
			$sql="update xAP_Widget_Location SET
			ColumnRef=".$c.",
			WidgetOrder=".$i."
			where LocationID=".intval(substr($value,2));
		
			dbexec($sql);
			$i++;
		}
		else
		{
		if(substr($value,0,9)=="newwidget"){
			$sql="insert into xAP_Widget_Location (ColumnRef,WidgetOrder,IP,WidgetID) VALUES (
					".$c.",
					".$i.",
					'".$ip."',
					'".intval(substr(($value),9))."'
			)";
			dbexec($sql);
		}
		$i++;
		}
}
}

?>